package cc.telecomdigital.tdstock.trading;

import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.trading.Common.Trade_AppConstant;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;

//This class contain the the activities for Purchase History, Stock Holding and Account Balance
public class Trade_AcctComboActivity extends TabActivity implements OnTabChangeListener
{
	/** Create the TabWidget appearance for the activity **/
	private View CreateCustomTabView(Context iContext, int iTextId, int iImageId)
	{
		View customView;
		TextView textView;
		ImageView imgView;

		customView = LayoutInflater.from(iContext).inflate(
				R.layout.at_imagetext_tabbut, null);
		textView = (TextView) customView
				.findViewById(R.id.at_imagetext_tabbut_text);
		imgView = (ImageView) customView
				.findViewById(R.id.at_imagetext_tabbut_img);

		textView.setText(iTextId);
		imgView.setImageDrawable(getResources().getDrawable(iImageId));
		return customView;
	}

	private TabHost	tabHost;

	@Override
	public void onCreate(Bundle iSaveInstance)
	{
		TabSpec tabSpec;

		super.onCreate(iSaveInstance);
		setContentView(R.layout.account_combo);

		// TabHost will have Tabs
		tabHost = (TabHost)findViewById(android.R.id.tabhost);
		tabHost.setup();
		
		View imgTxtButObj;

		imgTxtButObj = CreateCustomTabView(this,
				R.string.transHistoryText_abrev,
				R.drawable.at_stockorder_button);
		tabSpec = tabHost.newTabSpec("TH");
		tabSpec.setContent(new Intent(this, Trade_AcctOrder_SubActivity.class)
					.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
		tabSpec.setIndicator(imgTxtButObj);
		tabHost.addTab(tabSpec);

		imgTxtButObj = CreateCustomTabView(this,
				R.string.holdingBalText_abrev,
				R.drawable.at_stockhold_button);
		tabSpec = tabHost.newTabSpec("SH");
		tabSpec.setContent(new Intent(this, Trade_AcctHold_SubActivity.class)
				.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
		tabSpec.setIndicator(imgTxtButObj);
		tabHost.addTab(tabSpec);

		imgTxtButObj = CreateCustomTabView(this, R.string.acctBalText_abrev,
				R.drawable.at_stockbalance_button);
		tabSpec = tabHost.newTabSpec("AV");
		tabSpec.setContent(new Intent(this,
				Trade_AcctBalance_SubActivity.class)
				.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
		tabSpec.setIndicator(imgTxtButObj);
		tabHost.addTab(tabSpec);
						
		// Update base on page Context
		Intent inIntentObj;

		inIntentObj = getIntent();
		if (inIntentObj != null)
		{
			if (inIntentObj.hasExtra(Trade_AppConstant.tradingStateBundle))
				curStateType = inIntentObj.getIntExtra( Trade_AppConstant.tradingStateBundle, 0);
		}
		
		if (curStateType != 0)
			tabHost.setCurrentTab(curStateType);
		tabHost.setOnTabChangedListener(this);		
	}

	private static int curStateType = 0;	
	
	@Override
	public void onTabChanged(String arg0)
	{
		//Update Tab Index
		curStateType = tabHost.getCurrentTab();		
	}
}
